using System;
using System.Windows.Forms;
using System.Drawing;

namespace HIS
{
    public class MainForm : Form
    {
        private MenuStrip menuStrip;
        private ToolStripMenuItem tsmiPatient;
        private ToolStripMenuItem tsmiMedical;
        private ToolStripMenuItem tsmiStatistics;
        private ToolStripMenuItem tsmiSystem;
        private ToolStrip toolStrip;
        private StatusStrip statusStrip;
        private Panel mainPanel;
        private Label lblWelcome;
        private TableLayoutPanel buttonPanel;

        public MainForm()
        {
            InitializeComponents();
        }

        private void InitializeComponents()
        {
            // 窗体设置
            this.Text = "医院信息系统";
            this.Size = new Size(1024, 768);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.WindowState = FormWindowState.Maximized;

            // 创建菜单栏
            menuStrip = new MenuStrip();
            
            // 患者管理菜单
            tsmiPatient = new ToolStripMenuItem("患者管理");
            tsmiPatient.DropDownItems.AddRange(new ToolStripItem[] {
                new ToolStripMenuItem("叫号", null, (s, e) => new CallPatientForm().Show()),
                new ToolStripMenuItem("诊断录入", null, (s, e) => new DiagnosisForm().Show()),
                new ToolStripMenuItem("门诊医嘱", null, (s, e) => new MedicalOrderForm().Show()),
                new ToolStripMenuItem("门诊病历", null, (s, e) => new MedicalRecordForm().Show()),
                new ToolStripMenuItem("打印", null, (s, e) => new PrintForm().Show()),
                new ToolStripMenuItem("预约", null, (s, e) => new AppointmentForm().Show()),
                new ToolStripMenuItem("入院", null, (s, e) => new AdmissionForm().Show())
            });

            // 医疗管理菜单
            tsmiMedical = new ToolStripMenuItem("医疗管理");
            tsmiMedical.DropDownItems.AddRange(new ToolStripItem[] {
                new ToolStripMenuItem("传染病报卡", null, (s, e) => new InfectiousDiseaseForm().Show()),
                new ToolStripMenuItem("历史信息查询", null, (s, e) => new HistoryQueryForm().Show()),
                new ToolStripMenuItem("模板维护", null, (s, e) => new TemplateForm().Show())
            });

            // 统计管理菜单
            tsmiStatistics = new ToolStripMenuItem("统计管理");
            tsmiStatistics.DropDownItems.AddRange(new ToolStripItem[] {
                new ToolStripMenuItem("门诊工作量统计", null, (s, e) => new WorkloadForm().Show())
            });

            // 系统管理菜单
            tsmiSystem = new ToolStripMenuItem("系统管理");
            tsmiSystem.DropDownItems.AddRange(new ToolStripItem[] {
                new ToolStripMenuItem("实习生管理", null, (s, e) => new InternForm().Show()),
                new ToolStripMenuItem("系统消息", null, (s, e) => new MessageForm().Show()),
                new ToolStripSeparator(),
                new ToolStripMenuItem("退出系统", null, (s, e) => Application.Exit())
            });

            // 添加菜单项到菜单栏
            menuStrip.Items.AddRange(new ToolStripItem[] {
                tsmiPatient,
                tsmiMedical,
                tsmiStatistics,
                tsmiSystem
            });

            // 创建工具栏
            toolStrip = new ToolStrip();
            toolStrip.Items.AddRange(new ToolStripItem[] {
                new ToolStripButton("叫号", null, (s, e) => new CallPatientForm().Show()),
                new ToolStripButton("诊断录入", null, (s, e) => new DiagnosisForm().Show()),
                new ToolStripButton("门诊医嘱", null, (s, e) => new MedicalOrderForm().Show()),
                new ToolStripButton("门诊病历", null, (s, e) => new MedicalRecordForm().Show()),
                new ToolStripSeparator(),
                new ToolStripButton("传染病报卡", null, (s, e) => new InfectiousDiseaseForm().Show()),
                new ToolStripButton("历史查询", null, (s, e) => new HistoryQueryForm().Show()),
                new ToolStripSeparator(),
                new ToolStripButton("退出", null, (s, e) => Application.Exit())
            });

            // 创建状态栏
            statusStrip = new StatusStrip();
            statusStrip.Items.AddRange(new ToolStripItem[] {
                new ToolStripStatusLabel("就绪"),
                new ToolStripStatusLabel("用户：admin"),
                new ToolStripStatusLabel("角色：医生"),
                new ToolStripStatusLabel("时间：" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
            });

            // 创建主面板
            mainPanel = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = Color.White
            };

            // 创建欢迎标签
            lblWelcome = new Label
            {
                Text = "欢迎使用医院信息系统",
                Font = new Font("微软雅黑", 24, FontStyle.Bold),
                AutoSize = true,
                Location = new Point(300, 20)
            };
            mainPanel.Controls.Add(lblWelcome);

            // 创建按钮面板
            buttonPanel = new TableLayoutPanel
            {
                ColumnCount = 4,
                RowCount = 3,
                Dock = DockStyle.Fill,
                Padding = new Padding(20),
                Margin = new Padding(20)
            };
            buttonPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
            buttonPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
            buttonPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
            buttonPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
            buttonPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33F));
            buttonPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33F));
            buttonPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33F));

            // 添加功能按钮
            AddButton("叫号", new CallPatientForm());
            AddButton("诊断录入", new DiagnosisForm());
            AddButton("门诊医嘱", new MedicalOrderForm());
            AddButton("门诊病历", new MedicalRecordForm());
            AddButton("打印", new PrintForm());
            AddButton("预约", new AppointmentForm());
            AddButton("入院", new AdmissionForm());
            AddButton("传染病报卡", new InfectiousDiseaseForm());
            AddButton("历史查询", new HistoryQueryForm());
            AddButton("模板维护", new TemplateForm());
            AddButton("工作量统计", new WorkloadForm());
            AddButton("实习生管理", new InternForm());

            // 设置按钮面板位置
            buttonPanel.Location = new Point(0, 80);
            buttonPanel.Size = new Size(mainPanel.Width, mainPanel.Height - 100);

            mainPanel.Controls.Add(buttonPanel);

            // 设置菜单栏
            this.MainMenuStrip = menuStrip;

            // 添加控件到窗体
            this.Controls.AddRange(new Control[] {
                menuStrip,
                toolStrip,
                mainPanel,
                statusStrip
            });
        }

        private void AddButton(string text, Form form)
        {
            Button btn = new Button
            {
                Text = text,
                Font = new Font("微软雅黑", 12),
                Dock = DockStyle.Fill,
                Margin = new Padding(10),
                FlatStyle = FlatStyle.Flat
            };
            btn.Click += (s, e) => form.Show();
            buttonPanel.Controls.Add(btn);
        }
    }
} 